package com.example.common.config.common.orika;

import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * <p>
 *
 * </p>
 *
 * @author zyred
 * @since v 0.1
 **/
@Slf4j
@Lazy
@Configuration
@ConditionalOnClass(DefaultMapperFactory.class)
public class OrikaFactoryBeanConfig implements FactoryBean<MapperFactory> {

    @Override
    public MapperFactory getObject() throws Exception {
        log.info(">>>>>>>>>>>>>>>> common rest orika init starting >>>>>>>>>>>>>>>>>>>>>");
        return new DefaultMapperFactory.Builder().build();
    }

    @Override
    public Class<?> getObjectType() {
        return MapperFactory.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
